﻿// =================================================================== 
// 数据访问层(GDIT.DAL)
//====================================================================
// 文件：DCollegeInfo.cs
// 项目名称：学院网站
// 创建时间：2012-08-08
// 负责人：ChenZhiGang
//引用DevExpress.Data.Filtering，DevExpress.Xpo程序集
// 程序集介绍：学院概况信息数据访问层
// ===================================================================
using GDIT.Model;
using DevExpress.Data.Filtering;
using DevExpress.Xpo;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GDIT.Pattern;

namespace GDIT.DAL
{
    public class DCollegeInfo : ICollegeInfo
    {

        private XpoHelper.Test<Mtb_CollegeInfo> userOperation = null;

        /// <summary>
        /// 新增校园概况
        /// </summary>
        /// <param name="detailMenu">需要新增的校园概况对象</param>
        /// <returns>1：新增成功 2：新增失败</returns>
        public int InsertCollegeInfo(Mtb_CollegeInfo collegeInfo)
        {
            return XpoHelper.SaveAdded(collegeInfo);
        }

        /// <summary>
        /// 删除校园概况
        /// </summary>
        /// <param name="detailMenu">需要删除的校园概况对象</param>
        /// <returns>1：删除成功 0:删除失败</returns>
        public int DeleteCollegeInfo(Mtb_CollegeInfo collegeInfo)
        {
            userOperation = new XpoHelper.Test<Mtb_CollegeInfo>();
            return userOperation.Delete(collegeInfo.OID);
        }

        /// <summary>
        /// 更新校园概况
        /// </summary>
        /// <param name="detailMenu">需要更新的校园概况对象</param>
        /// <returns>1：更新成功 0：更新失败</returns>
        public int UpdateCollegeInfo(Mtb_CollegeInfo collegeInfo)
        {
            userOperation = new XpoHelper.Test<Mtb_CollegeInfo>();
            XPCollection xp = userOperation.Operation("OID", collegeInfo.OID);
            foreach (Mtb_CollegeInfo b in xp)
            {
                b.CollegeInfoName = collegeInfo.CollegeInfoName;
                b.CollegeInfoContent = collegeInfo.CollegeInfoContent;
                b.CollegeType = collegeInfo.CollegeType;
                return XpoHelper.SaveModified(b);
            }
            return 0;
        }

        /// <summary>
        /// 查询单一校园概况
        /// </summary>
        /// <param name="CollegeInfo">需要查询的校园概况对象</param>
        /// <returns>所需的校园概况对象</returns>
        public Mtb_CollegeInfo SelectCollegeInfoByCollegeInfo(string name)
        {
            Mtb_CollegeInfo bulletin = null;
            userOperation = new XpoHelper.Test<Mtb_CollegeInfo>();
            XPCollection xp = userOperation.Operation("CollegeInfoName", name);
            foreach (Mtb_CollegeInfo b in xp)
            {
                bulletin = b;
            }
            return bulletin;
        }

        /// <summary>
        /// 查询所有的校园概况信息
        /// </summary>
        /// <returns>所有的校园概况信息</returns>
        public XPCollection SelectAllCollegeInfo(string collegeType)
        {
            userOperation = new XpoHelper.Test<Mtb_CollegeInfo>();
            XPCollection xp = userOperation.Operation("CollegeType",collegeType);
            return xp;
        }
    }
}
